#include<bits/stdc++.h>
#define int long long
using namespace std;
inline int read()
{
	int res=0,f=1;char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') f=-1;c=getchar();}
	while(c>='0'&&c<='9'){res=(res<<1)+(res<<3)+(c^48);c=getchar();}
	return res*f;
}
void write(int x)
{
	if(x<0)x=-x,putchar('-');
	if(x>9)write(x/10);
	putchar(x%10+'0');
}
int n,q;
int l[114514],r[114514]; 
signed main()
{
	freopen("study.in","r",stdin);
	freopen("study.out","w",stdout);
	n=read(),q=read();
	for(int i=2;i<=n;i++) l[i]=read(),r[i]=read();
	while(q--)
	{
		int op=read(),a=read(),b=read(),c=read(),d;
		if(op==1) l[a]=b,r[a]=c;
		else
		{
			int ans=0;
			d=read();
			if(a<c)
			{
				++a;
				for(int i=a;i<=c;i++)
				{
					if(l[i]>b) b=l[i];
					if(r[i]<=b) ans+=b-r[i]+1,b=r[i]-1;
					++b;
				}
				if(b>d) ans+=b-d;
			}
			else
			{
				++c;
				for(int i=a;i>=c;i--)
				{
					if(l[i]>b) b=l[i];
					if(r[i]<=b) ans+=b-r[i]+1,b=r[i]-1;
					++b;
				}
				if(b>d) ans+=b-d;
			}
			write(ans),puts("");
		}
	}
	return 0;
}
